﻿/*
 *    Copyright [2010] [Daniel Sawan]
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 */

package com.kikoulol.jarmory.extractor.xml;

import java.util.ArrayList;
import java.util.List;

import org.w3c.dom.Node;

import com.kikoulol.jarmory.extractor.enums.Regions;

/**
 * 
 * Property whose getter do not fire super.setupXml() method : teamUrl
 * 
 */
public class TeamInfo extends AbstractArmoryXmlFile
{
  private String teamUrl;

  private List<CharacterSheet> characters = new ArrayList<CharacterSheet>();

  private String battleGroup;
  private String created;
  private String faction;
  private String factionId;
  private String gamesPlayed;
  private String gamesWon;
  private String lastSeasonRanking;
  private String name;
  private String ranking;
  private String rating;
  private String realm;
  private String realmUrl;
  private String relevance;
  private String season;
  private String seasonGamesPlayed;
  private String seasonGamesWon;
  private String size;
  private String teamSize;
  private String teamUrlEscape;
  private String url;

  /**
   * 
   * @param region
   * @param teamQueryString
   */
  public TeamInfo(Regions region, String teamQueryString)
  {
    super(region, "team-info.xml?" + teamQueryString);
  }

  /**
   * 
   */
  protected void initProperties()
  {
    Node teamInfoNode =   this.getXml().getElementsByTagName("arenaTeam").item(0);

    this.name =           this.getNamedItemValue(teamInfoNode, "name");
    this.battleGroup =    this.getNamedItemValue(teamInfoNode, "battleGroup");
    this.created =        this.getNamedItemValue(teamInfoNode, "created");
    this.faction =        this.getNamedItemValue(teamInfoNode, "faction");
    this.factionId =      this.getNamedItemValue(teamInfoNode, "factionId");
    this.gamesPlayed =    this.getNamedItemValue(teamInfoNode, "gamesPlayed");
    this.gamesWon =       this.getNamedItemValue(teamInfoNode, "gamesWon");
    this.lastSeasonRanking = this.getNamedItemValue(teamInfoNode, "lastSeasonRanking");
    this.ranking =        this.getNamedItemValue(teamInfoNode, "ranking");
    this.rating =         this.getNamedItemValue(teamInfoNode, "rating");
    this.realm =          this.getNamedItemValue(teamInfoNode, "realm");
    this.realmUrl =       this.getNamedItemValue(teamInfoNode, "realmUrl");
    this.relevance =      this.getNamedItemValue(teamInfoNode, "relevance");
    this.season =         this.getNamedItemValue(teamInfoNode, "season");
    this.seasonGamesPlayed = this.getNamedItemValue(teamInfoNode, "seasonGamesPlayed");
    this.seasonGamesWon = this.getNamedItemValue(teamInfoNode, "seasonGamesWon");
    this.size =           this.getNamedItemValue(teamInfoNode, "size");
    this.teamSize =       this.getNamedItemValue(teamInfoNode, "teamSize");
    this.teamUrl =        this.getNamedItemValue(teamInfoNode, "teamUrl");
    this.teamUrlEscape =  this.getNamedItemValue(teamInfoNode, "teamUrlEscape");
    this.url =            this.getNamedItemValue(teamInfoNode, "url");
  }

  public String getBattleGroup()
  {
    super.setupXml();
    return battleGroup;
  }

  public List<CharacterSheet> getCharacters()
  {
    super.setupXml();
    return characters;
  }

  public String getCreated()
  {
    super.setupXml();
    return created;
  }

  public String getFaction()
  {
    super.setupXml();
    return faction;
  }

  public String getFactionId()
  {
    super.setupXml();
    return factionId;
  }

  public String getGamesPlayed()
  {
    super.setupXml();
    return gamesPlayed;
  }

  public String getGamesWon()
  {
    super.setupXml();
    return gamesWon;
  }

  public String getLastSeasonRanking()
  {
    super.setupXml();
    return lastSeasonRanking;
  }

  /**
   * 
   * @return
   */
  public List<CharacterSheet> getMembers()
  {
    super.setupXml();
    
    for (int i = 0; i < this.getXml().getElementsByTagName("character").getLength(); i++)
    {
      Node characterNode = this.getXml().getElementsByTagName("character").item(i);
      CharacterSheet character = new CharacterSheet(this.getRegion(), this.getNamedItemValue(characterNode, "charUrl"));
      //CharacterSheet character = new CharacterSheet(this.getRegion(), this.getNamedItemValue(characterNode, "realm"), this.getNamedItemValue(characterNode, "name"));
      
      this.characters.add(character);
    }

    return characters;
  }

  public String getName()
  {
    super.setupXml();
    return name;
  }

  public String getRanking()
  {
    super.setupXml();
    return ranking;
  }

  public String getRating()
  {
    super.setupXml();
    return rating;
  }

  public String getRealm()
  {
    super.setupXml();
    return realm;
  }

  public String getRealmUrl()
  {
    super.setupXml();
    return realmUrl;
  }

  public String getRelevance()
  {
    super.setupXml();
    return relevance;
  }

  public String getSeason()
  {
    super.setupXml();
    return season;
  }

  public String getSeasonGamesPlayed()
  {
    super.setupXml();
    return seasonGamesPlayed;
  }

  public String getSeasonGamesWon()
  {
    super.setupXml();
    return seasonGamesWon;
  }

  public String getSize()
  {
    super.setupXml();
    return size;
  }

  public String getTeamSize()
  {
    super.setupXml();
    return teamSize;
  }

  public String getTeamUrl()
  {
    super.setupXml();
    return teamUrl;
  }

  public String getTeamUrlEscape()
  {
    super.setupXml();
    return teamUrlEscape;
  }

  public String getUrl()
  {
    super.setupXml();
    return url;
  }
}